/*
 * @lc app=leetcode.cn id=78 lang=java
 *
 * [78] 子集
 */

// @lc code=start
import java.util.*;
class Solution {
    public List<List<Integer>> subsets(int[] nums) {
        backtracking(nums, 0);
        return res;
    }

    List<List<Integer>> res = new ArrayList<>();
    List<Integer> path = new ArrayList<>();

    private void backtracking(int[] nums, int startIndex) {
        res.add(new ArrayList<>(path));
        if(startIndex >= nums.length) {
            return;
        }

        for(int i = startIndex; i < nums.length; i++) {
            path.add(nums[i]);
            backtracking(nums, i+1);
            path.removeLast();
        }
    }
}
// @lc code=end

